package org.csu.mybigpro.persistence;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.csu.mybigpro.domain.ThumbsUp;

public interface ThumbsUpMapper extends BaseMapper<ThumbsUp> {


    default ThumbsUp searchByteacherIdAndReplyId(int replyId, String teacherId){
        LambdaQueryWrapper<ThumbsUp> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ThumbsUp::getReplyId, replyId);
        wrapper.eq(ThumbsUp::getUserId, teacherId);
        return selectOne(wrapper);
    }

    default int thumbsDown(String teacherId, int replyId){
        LambdaUpdateWrapper<ThumbsUp> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(ThumbsUp::getReplyId, replyId);
        wrapper.eq(ThumbsUp::getUserId, teacherId);
        wrapper.set(ThumbsUp::getThumbsUp, 0);
        return update(wrapper);
    }


    default int thumbsUp(String teacherId, int replyId){
        LambdaUpdateWrapper<ThumbsUp> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(ThumbsUp::getReplyId, replyId);
        wrapper.eq(ThumbsUp::getUserId, teacherId);
        wrapper.set(ThumbsUp::getThumbsUp, 1);
        return update(wrapper);
    }
}
